"""
根据逻辑处理需求，提供数据支持
"""
import pymysql
import re


class Dict:
    def __init__(self):

        self.kwargs = {

            "user": "root",
            "passwd": "123456",
            "database": "dict",
            "charset": "utf8"
        }
        self.db = pymysql.connect(**self.kwargs)
        self.cur = self.db.cursor()

    def close(self):

        self.cur.close()
        self.db.close()

    def register(self, name, passwd):
        sql = "insert into user (name,password) values (%s,%s);"
        try:
            self.cur.execute(sql, [name, passwd])
            self.db.commit()
            return True
        except Exception as e:
            print(e)
            self.db.rollback()
            return False

    def login(self, name, passwd):
        sql = "select id from user where name =%s and password=%s;"

        self.cur.execute(sql, [name, passwd])
        if self.cur.fetchone():
            return True
        else:
            return False

    def query(self, word):
        sql = "select mean from words where word=%s;"
        return self.cur.execute(sql, [word])  # (mean,)none

    def insert_hist(self):
        pass


if __name__ == '__main__':
    dict = Dict()

    dict.close()

if __name__ == '__main__':
    pass
